<template>
  <div>
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="120" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="inOutReport11asd"
      :columns="columns"
      :isMemoryPagination="true"
      :dataSource="formDataList"
      selectionType="multiple"
      :onRowSelectChange="rowSelectHandle"
      :onColumnsChange="columns => (this.columns = columns)"
      :isSelectColumn="true"
      :onSyncTableData="tableHandle"
      :isExportExcel="true"
      exportFileName="配件索赔查询.xlsx"
    >
      <!-- :params="fetchParams"
      :fetchapi="fetchApi" -->
      <!-- :datakey="'rows'" -->
      <template slot="controls">
        <el-button size="small" type="primary" @click="addRecordHandle">确认索赔</el-button>
      </template>
    </FilterTable>
  </div>
</template>

<script>
/*
 *
 * 配件索赔查询
 */

import { authority } from '@/utils/authMixin';
import { claimInquiryInfo, claimConfirmInfo } from '@/api/part/report/claimInquiry';
import moment from 'moment';
export default {
  name: 'inOutReport',
  components: {},
  mixins: [authority],
  data() {
    this.selectedRow = [];
    this.confirmList = [];
    return {
      visible: false,
      topFilterList: this.createTopFilters(),
      fetchApi: claimInquiryInfo,
      columns: this.createTableColumns(),
      fetchParams: { xhrAbort: true },
      formData: {}, // 向子组件传数据的数组
      tableData: [], // 表单数据
      formDataList: [] // 内存分页
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.initQuery();
  },
  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '索赔单据',
          fieldName: 'I_SPDH'
        },

        {
          type: 'RANGE_DATE',
          label: '索赔申请日期',
          dateType: 'daterange',
          initialValue: [
            moment()
              .startOf('month')
              .format('YYYY-MM-DD'),
            moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
          ],
          style: { minWidth: '120px' },
          fieldName: 'I_SQDATS|I_SQDATE'
        },
        {
          type: 'INPUT',
          label: '发运单号',
          fieldName: 'I_DVBELN'
        },
        {
          type: 'INPUT',
          label: '上报中转库',
          fieldName: 'I_LGORT'
        },
        {
          type: 'SELECT',
          label: '是否确认索赔',
          fieldName: 'I_UNCFM',
          itemList: [
            { text: '全部', value: '' },
            { text: '是', value: '0' },
            { text: '否', value: '1' }
          ]
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'I_MATNR'
        },
        {
          type: 'SELECT',
          label: '配件索赔类型',
          fieldName: 'I_SPLX',
          itemList: [
            { text: '全部', value: '' },
            { text: '错', value: 'C' },
            { text: '亏', value: 'K' },
            { text: '缺', value: 'Q' },
            { text: '损', value: 'S' },
            { text: '赢', value: 'Y' }
          ]
        },
        {
          type: 'SELECT',
          label: '申请类型',
          fieldName: 'I_SQLX',
          itemList: [
            { text: '全部', value: '' },
            { text: '补发', value: 'BF' },
            { text: '实物返还', value: 'FH' },
            { text: '赔付', value: 'PF' },
            { text: '退换', value: 'TH' },
            { text: '退库', value: 'TK' }
          ]
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '配件索赔单号',
          dataIndex: 'SPDH',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '年份',
          dataIndex: 'MJAHR',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '配件代码',
          dataIndex: 'MATNR',
          width: '160',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },

        {
          title: '配件名称',
          dataIndex: 'NAME1',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '发货单号',
          dataIndex: 'VBELN',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '是否赔付',
          dataIndex: 'PC',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '单据状态',
          dataIndex: 'DJZT',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '申请日期',
          dataIndex: 'SQDAT',
          dateFormat: 'yyyy-MM-dd',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '申请时间',
          dataIndex: 'SQZET',
          align: 'center',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '受理日期',
          dataIndex: 'SLDAT',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '受理时间',
          dataIndex: 'SLZET',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '索赔完成日期',
          dataIndex: 'WCDAT',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '索赔完成时间',
          dataIndex: 'WCZET',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '签收时是否提出问题',
          dataIndex: 'QS',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '经销商',
          dataIndex: 'KUNNR',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '经销商名称',
          dataIndex: 'NAME2',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '上报中转库',
          dataIndex: 'LGORT',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '索赔原因',
          dataIndex: 'JTQK',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '订货方式',
          dataIndex: 'FHFSS',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '索赔类型',
          dataIndex: 'DEC1',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '申请类型',
          dataIndex: 'DEC2',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '索赔数量',
          dataIndex: 'SPSL',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          showOverflowTooltip: true
        },
        {
          title: '单价',
          dataIndex: 'NETPR',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          showOverflowTooltip: true
        },
        {
          title: '金额',
          dataIndex: 'JE',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          showOverflowTooltip: true
        },
        {
          title: '责任方',
          dataIndex: 'ZRF',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '承运商',
          dataIndex: 'TDLNR',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '处理结果',
          dataIndex: 'CLJG',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '否辖区内',
          dataIndex: 'XQ',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '所属中转库',
          dataIndex: 'LGORT1',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '申请人',
          dataIndex: 'SQNAM',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '受理人',
          dataIndex: 'SLNAM',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '索赔完成人',
          dataIndex: 'WCNAM',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '经销商确认索赔日期',
          dataIndex: 'QRDAT',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '经销商确认索赔时间',
          dataIndex: 'QRZET',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '经销商确认索赔人',
          dataIndex: 'QRNAM',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
      ];
    },
    // 初始化查询
    async initQuery() {
      let fiterData = await this.$refs.topFilter.GET_FORM_DATA();
      this.fetchParams = Object.assign(this.fetchParams, fiterData[1], {
        ImportParameter: fiterData[1],
        xhrAbort: false
      });
    },
    // 搜索
    async changeHandle(val) {
      this.formDataList = [];
      // 去除空串
      for (let i in val) {
        if (val[i] == '') {
          val[i] = undefined;
        }
      }
      let res = await claimInquiryInfo(Object.assign(this.fetchParams, { ImportParameter: val, xhrAbort: false }, val));
      this.formDataList = res.data;
      // this.fetchParams.xhrAbort = true;
      // this.fetchParams = Object.assign(this.fetchParams, { ImportParameter: val, xhrAbort: false }, val);
      // this.columns = [...this.columns];
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // 查询仓库代码
    findWareHouseModal() {
      this.visible = true;
    },
    // 回显仓库信息
    // madol数据处理
    dataHandler(val) {
      this.topFilterList[0].initialValue = val.storageCode;
      // this.topFilterList[1].initialValue = val[0].storageName;
      // this.mainId = val[0].id;
      this.visible = false;
    },
    // table动态回调函数
    tableHandle(val) {
      this.tableData = val;
      console.log(this.tableData);
    },
    // 行选中事件
    rowSelectHandle(rows) {
      this.selectedRow = rows;
    },
    async addRecordHandle() {
      // 校验是否空表单
      if (!this.selectedRow || this.selectedRow.length < 1) {
        return this.$notify.error({ title: '提示信息', message: '请选中一条数据' });
      }
      console.log(this.selectedRow, '选中数据');
      let params = {};
      params.TableParameter = {};
      params.ImportParameter = { I_WXZ: '' };
      params.TableParameter.IT_BJSP_CONFIRM = this.selectedRow;
      const res = await claimConfirmInfo(params);
      if (res.resultCode == 200) {
        this.$notify.success({ title: '提示信息', message: '保存成功!' });
        this.fetchParams = { ...this.fetchParams };
        // 需要主页面刷新
        this.closeHandler('refresh');
      }
    },

    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
